package com.ruoyi.project.warehouseSystem.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.warehouseSystem.domain.ComptClassify;
import com.ruoyi.project.warehouseSystem.service.IComptClassifyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 配件分类Controller
 * 
 * @author wangshuo
 * @date 2021-01-22
 */
@RestController
@RequestMapping("/warehouseSystem/comptClassify")
public class ComptClassifyController extends BaseController
{
    @Autowired
    private IComptClassifyService comptClassifyService;

    /**
     * 查询配件分类列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:comptClassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComptClassify comptClassify)
    {
        startPage();
        List<ComptClassify> list = comptClassifyService.selectComptClassifyList(comptClassify);
        return getDataTable(list);
    }

    /**
     * 导出配件分类列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:comptClassify:export')")
    @Log(title = "配件分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ComptClassify comptClassify)
    {
        List<ComptClassify> list = comptClassifyService.selectComptClassifyList(comptClassify);
        ExcelUtil<ComptClassify> util = new ExcelUtil<ComptClassify>(ComptClassify.class);
        return util.exportExcel(list, "comptClassify");
    }

    /**
     * 获取配件分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:comptClassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(comptClassifyService.selectComptClassifyById(id));
    }

    /**
     * 新增配件分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:comptClassify:add')")
    @Log(title = "配件分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComptClassify comptClassify)
    {
        return toAjax(comptClassifyService.insertComptClassify(comptClassify));
    }

    /**
     * 修改配件分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:comptClassify:edit')")
    @Log(title = "配件分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComptClassify comptClassify)
    {
        return toAjax(comptClassifyService.updateComptClassify(comptClassify));
    }

    /**
     * 删除配件分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:comptClassify:remove')")
    @Log(title = "配件分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(comptClassifyService.deleteComptClassifyByIds(ids));
    }

    /**
     * 获取配件分类下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(ComptClassify comptClassify)
    {
        List<ComptClassify> comptClassifies = comptClassifyService.selectComptClassifyList(comptClassify);
        return AjaxResult.success(comptClassifyService.buildComptClassifyTreeSelect(comptClassifies));
    }
}
